

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon%2032x32.ico">
  <link rel="icon" href="/img/favicon%2032x32.ico">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="hypocrite30">
  <meta name="keywords" content="">
  
  <title>Java算法竞赛常用模板 - hypocrite30</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.4.0/styles/idea.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"hypocrite30.gitee.io","root":"/","version":"1.8.9","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":"§"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":"b5f391eebc7eaea88e68a49d5924e381","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.3.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Hypocrite30 BLOG</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/postPage.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Java算法竞赛常用模板">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-02-10 12:15" pubdate>
        2021年2月10日 中午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      41
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Java算法竞赛常用模板</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2021年3月27日 晚上
                
              </p>
            
            <div class="markdown-body">
              <h1 id="Java算法竞赛常用模板"><a href="#Java算法竞赛常用模板" class="headerlink" title="Java算法竞赛常用模板"></a>Java算法竞赛常用模板</h1><h2 id="一、输入输出"><a href="#一、输入输出" class="headerlink" title="一、输入输出"></a>一、输入输出</h2><h3 id="简单输入"><a href="#简单输入" class="headerlink" title="简单输入"></a>简单输入</h3><figure class="highlight java"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.Scanner <br><span class="hljs-keyword">import</span> java.io.BufferedInputStream;<br><br>Scanner sc1 = <span class="hljs-keyword">new</span> Scanner(System.in);<br>Scanner sc2 = <span class="hljs-keyword">new</span> Scanner(<span class="hljs-keyword">new</span> BufferedInputStream(System.in));<br><span class="hljs-comment">// sc2用到缓冲流，读入更快</span><br></code></pre></div></td></tr></table></figure>
<p>测试：</p>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml">public static void main(String<span class="hljs-literal">[]</span> args) &#123;<br>        long t1, t2, t3;<br>        Scanner sc1 = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Scanner(System.<span class="hljs-params">in</span>)</span>;<br>        Scanner sc2 = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Scanner(<span class="hljs-params">new</span> BufferedInputStream(System.<span class="hljs-params">in</span>)</span>);<br><br>        t1 = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>nano<span class="hljs-constructor">Time()</span>;<br>        String next = sc1.next<span class="hljs-literal">()</span>;<br>        t2 = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>nano<span class="hljs-constructor">Time()</span>;<br>        t3 = t2 - t1;<br>        <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-string">&quot;sc1:&quot;</span> + t3);<br>        <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(next);<br><br>        t1 = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>nano<span class="hljs-constructor">Time()</span>;<br>        String next2 = sc2.next<span class="hljs-literal">()</span>;<br>        t2 = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>nano<span class="hljs-constructor">Time()</span>;<br>        t3 = t2 - t1;<br>        <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-string">&quot;sc2:&quot;</span> + t3);<br>        <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(next2);<br>    &#125;<br></code></pre></div></td></tr></table></figure>
<blockquote>
<p>abc<br>sc1:7968695900<br>abc<br>abc<br>sc2:1945031900<br>abc</p>
</blockquote>
<h3 id="复杂输入"><a href="#复杂输入" class="headerlink" title="复杂输入"></a>复杂输入</h3><div class="hljs code-wrapper"><pre><code>    如：1,2,3,4,5
</code></pre></div>
<figure class="highlight processing"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs processing"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> main(<span class="hljs-keyword">String</span>[] args) &#123;<br>    Scanner sc = <span class="hljs-keyword">new</span> Scanner(System.in);<br>    <span class="hljs-keyword">String</span> <span class="hljs-built_in">str</span> = sc.next();<br>    <span class="hljs-keyword">String</span>[] <span class="hljs-built_in">split</span> = <span class="hljs-built_in">str</span>.<span class="hljs-built_in">split</span>(<span class="hljs-string">&quot;,&quot;</span>);<br>    <span class="hljs-built_in">int</span>[] strInt = <span class="hljs-keyword">new</span> <span class="hljs-built_in">int</span>[<span class="hljs-built_in">split</span>.length];<br>    <span class="hljs-keyword">for</span> (<span class="hljs-built_in">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-built_in">split</span>.length; i++) &#123;<br>        strInt[i] = Integer.parseInt(<span class="hljs-built_in">split</span>[i]);<br>    &#125;<br>    System.out.<span class="hljs-built_in">println</span>(Arrays.toString(strInt));<br>&#125;<br></code></pre></div></td></tr></table></figure>
<blockquote>
<p>1,2,3,4,5<br>[1, 2, 3, 4, 5]</p>
</blockquote>
<h3 id="文件输入"><a href="#文件输入" class="headerlink" title="文件输入"></a>文件输入</h3><div class="hljs code-wrapper"><pre><code>    用于大数据的读入，不用手动输入那么麻烦。BufferedInputStream缓冲流来加速，文件输入流用**绝对路径**，避免不必要的麻烦，要不就把资源文件放在src目录下。
</code></pre></div>
<figure class="highlight haxe"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs haxe"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> void main(<span class="hljs-keyword">String</span>[] args) throws FileNotFoundException &#123;<br>    Scanner sc = <span class="hljs-keyword">new</span> <span class="hljs-type">Scanner</span>(<span class="hljs-keyword">new</span> <span class="hljs-type">BufferedInputStream</span>(<span class="hljs-keyword">new</span> <span class="hljs-type"></span><br><span class="hljs-type"></span>    FileInputStream(<span class="hljs-string">&quot;E:\\input.txt&quot;</span>)));<br>    List&lt;Integer&gt; list = <span class="hljs-keyword">new</span> <span class="hljs-type">ArrayList</span>&lt;&gt;();<br>    <span class="hljs-keyword">while</span> (sc.hasNext()) &#123;<br>        list.add(sc.nextInt());<br>    &#125;<br>    System.out.println(list);<br>&#125;<br></code></pre></div></td></tr></table></figure>
<h2 id="二、数据类型"><a href="#二、数据类型" class="headerlink" title="二、数据类型"></a>二、数据类型</h2><h3 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h3><ul>
<li>按照空格分割字符串</li>
</ul>
<figure class="highlight processing"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs processing"><span class="hljs-keyword">String</span>[] s=<span class="hljs-built_in">str</span>.<span class="hljs-built_in">split</span>(<span class="hljs-string">&quot; +&quot;</span>);<br><span class="hljs-keyword">String</span>[] s=<span class="hljs-built_in">str</span>.<span class="hljs-built_in">split</span>(<span class="hljs-string">&quot;\\s+&quot;</span>);<br><span class="hljs-comment">// 以一个或多个空格分割</span><br></code></pre></div></td></tr></table></figure>
<ul>
<li><p><strong>public int indexOf(String str)：</strong>返回字符串中第一次出现str的位置；</p>
</li>
<li><p><strong>public int indexOf(String str,int fromIndex)：</strong>返回字符串从fromIndex开始第一次出现str的位置；</p>
</li>
<li><p><strong>public String substring(int beginIndex)：</strong>返回该字符串从beginIndex开始到结尾的子字符串；</p>
</li>
<li><p><strong>public String substring(int beginIndex,int endIndex)：</strong>返回该字符串从beginIndex开始到endsIndex结尾的子字符串</p>
</li>
<li><p><strong>public char[] toCharArray ()</strong> <strong>：</strong>将此字符串转换为新的字符数组</p>
</li>
<li><p><strong>public String replace (CharSequence target, CharSequence replacement)</strong> <strong>：</strong>将与target匹配的字符串使用replacement字符串替换。</p>
</li>
<li><p><strong>String replaceAll(String regex, String replacement)：</strong>使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串</p>
</li>
</ul>
<figure class="highlight processing"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs processing"><span class="hljs-keyword">String</span> ss=<span class="hljs-built_in">str</span>.replaceAll(<span class="hljs-string">&quot; +&quot;</span>, <span class="hljs-string">&quot;,&quot;</span>);<br><span class="hljs-keyword">String</span> ss=<span class="hljs-built_in">str</span>.replaceAll(<span class="hljs-string">&quot;\\s+&quot;</span>, <span class="hljs-string">&quot;,&quot;</span>);<br><span class="hljs-comment">// 二者都能把一个或多个空格换成逗号</span><br></code></pre></div></td></tr></table></figure>
<h3 id="大数"><a href="#大数" class="headerlink" title="大数"></a>大数</h3><figure class="highlight stylus"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs stylus"><span class="hljs-comment">//BigDecimal类型构造方法</span><br><span class="hljs-function"><span class="hljs-title">BigDecimal</span><span class="hljs-params">(double val)</span></span><br>          <span class="hljs-comment">//将 double 转换为 BigDecimal，后者是 double 的二进制浮点值准确的十进制表示形式。</span><br><span class="hljs-function"><span class="hljs-title">BigDecimal</span><span class="hljs-params">(int val)</span></span><br>          <span class="hljs-comment">//将 int 转换为 BigDecimal。</span><br><span class="hljs-function"><span class="hljs-title">BigDecimal</span><span class="hljs-params">(long val)</span></span><br>          <span class="hljs-comment">//将 long 转换为 BigDecimal。</span><br><span class="hljs-function"><span class="hljs-title">BigDecimal</span><span class="hljs-params">(String val)</span></span><br>          <span class="hljs-comment">//将 BigDecimal 的字符串表示形式转换为 BigDecimal。</span><br><span class="hljs-comment">//BigInteger类型构造方法</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(int val)</span></span><br>          <span class="hljs-comment">//将 int 转换为 BigInteger。</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(String val)</span></span><br>          <span class="hljs-comment">//将 BigDecimal 的字符串表示形式转换为 BigInteger。</span><br><span class="hljs-comment">//BigInteger转换方法</span><br>BigInteger valueOf(long val)<br>          <span class="hljs-comment">//返回其值等于指定 long 的值的 BigInteger。</span><br>		  <span class="hljs-comment">//如：BigInteger bi1=new BigInteger(1000);</span><br><span class="hljs-comment">//通用方法</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.max</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//返回最大数</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.min</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//返回最小数</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.add</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//相当于：+</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.subtract</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//相当于：-</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.multiply</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//相当于：*</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.divide</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//相当于：/</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.mod</span>(BigInteger(BigDecimal))<br>    <span class="hljs-comment">//相当于：%</span><br><span class="hljs-function"><span class="hljs-title">BigInteger</span><span class="hljs-params">(BigDecimal)</span></span><span class="hljs-selector-class">.abs</span>()<br>    <span class="hljs-comment">//返回其值是此 BigIntege(BigDecimal)r 的绝对值的 BigInteger(BigDecimal)。</span><br></code></pre></div></td></tr></table></figure>
<h3 id="Calendar类"><a href="#Calendar类" class="headerlink" title="Calendar类"></a>Calendar类</h3><ul>
<li>Calendar实例化</li>
</ul>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml">Calendar calendar = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Calendar</span>.</span></span>get<span class="hljs-constructor">Instance()</span>;<br></code></pre></div></td></tr></table></figure>
<ul>
<li><strong>YEAR</strong>       指示年的 get 和 set 的字段数字。</li>
<li><strong>MONTH</strong>  指示月份的 get 和 set 的字段数字。</li>
<li><strong>DATE</strong>       指示日的 get 和 set 的字段数字。-</li>
<li><strong>HOUR</strong>       get 和 set 的字段数字,指示当天中的某小时</li>
<li><strong>MINUTE</strong> get 和 set 的字段数字,指示当前小时中的某分钟</li>
<li><strong>SECOND</strong> get 和 set 的字段数字,指示当前分钟中的某秒</li>
<li><strong>DAY_OF_MONTH</strong>   get 和 set 的字段数字, 指示以月为起点过了几天。</li>
<li><strong>DAY_OF_WEEK</strong>   get 和 set 的字段数字, 指示以周为起点过了几天。</li>
<li><strong>DAY_OF_YEAR</strong>   get 和 set 的字段数字, 指示以年为起点过了几天。</li>
<li><strong>DAY_OF_WEEK_IN_MONTH</strong>   get 和 set 的字段数字, 指示当前月中的第几个星期。</li>
</ul>
<blockquote>
<p>public static final int SUNDAY = 1;</p>
<p>public static final int JANUARY = 0;</p>
<p>以上表示，一周的开始是周日，即为1，以此类推。</p>
<p>一年的开始是一月，即为0，所以对月的设置要 - 1，对月的读取要 + 1</p>
</blockquote>
<div class="hljs code-wrapper"><pre><code>    `get(int field); `// 获取给定字段的值，field即上面的字段数字
</code></pre></div>
<figure class="highlight stata"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs stata">Calendar calendar = Calendar.getInstance();<br><span class="hljs-comment">// 设置日期为: 2020.1.21</span><br>calendar.<span class="hljs-keyword">set</span>(Calendar.YEAR, 2020);<br>calendar.<span class="hljs-keyword">set</span>(Calendar.MONTH, 0);<br>calendar.<span class="hljs-keyword">set</span>(Calendar.DAY_OF_MONTH, 21);<br><span class="hljs-comment">// 获取2020.1.21是星期几</span><br>System.<span class="hljs-keyword">out</span>.<span class="hljs-keyword">print</span>(calendar.<span class="hljs-built_in">get</span>(Calendar.DAY_OF_WEEK));<br><br>输出：<br>3 <span class="hljs-comment">// 3代表星期二</span><br></code></pre></div></td></tr></table></figure>
<h4 id="Calendar类与Date类的转换"><a href="#Calendar类与Date类的转换" class="headerlink" title="Calendar类与Date类的转换"></a>Calendar类与Date类的转换</h4><ul>
<li><p>Date类</p>
<div class="hljs code-wrapper"><pre><code>  Date date = new Date();
  System.out.println(&quot;毫秒:&quot;+date.getTime());//输入毫秒
   
  //时间转字符串
  SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);
  String time = sdf.format(date);
  System.out.println(&quot;时间转字符串:&quot;+time);
   
  //利用字符串来转时间格式（记得抛出异常）
  String time02 = &quot;2018-09-05&quot;;
  SimpleDateFormat  sdf2 = new SimpleDateFormat (&quot;yyyy-MM-dd&quot;);
  Date date2 = sdf2.parse(time02);
  System.out.println(&quot;字符串转时间格式：&quot;+date2);
</code></pre></div>
</li>
<li><p>Calendar类</p>
<div class="hljs code-wrapper"><pre><code>  // 使用默认时区和语言环境获得一个日历
  Calendar cal = Calendar.getInstance();
  // 赋值时年月日时分秒常用的6个值，注意月份下标从0开始，所以取月份要+1
  System.out.println(&quot;年:&quot; + cal.get(Calendar.YEAR));
  System.out.println(&quot;月:&quot; + (cal.get(Calendar.MONTH) + 1));
  System.out.println(&quot;日:&quot; + cal.get(Calendar.DAY_OF_MONTH));
  System.out.println(&quot;时:&quot; + cal.get(Calendar.HOUR_OF_DAY));
  System.out.println(&quot;分:&quot; + cal.get(Calendar.MINUTE));
  System.out.println(&quot;秒:&quot; + cal.get(Calendar.SECOND));
   
  //手动设置某个日期
  Calendar cal02 = Calendar.getInstance();
  //注意，设置时间的时候月份的下标是在0开始的
  //设置时间不一定要这6个参数3个参数也是可以的
  cal02.set(2018,9,1,12,0,0);//二零一八年十月一号十二点
  System.out.println(cal02.getTime());//getTime()返回Date类型
</code></pre></div>
</li>
<li><p>Calendar转换为Date</p>
</li>
</ul>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml">Calendar cal = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Calendar</span>.</span></span>get<span class="hljs-constructor">Instance()</span>;<br>Date date = cal.get<span class="hljs-constructor">Time()</span>;<br>SimpleDateFormat simpleDateFormat = <span class="hljs-keyword">new</span> <span class="hljs-constructor">SimpleDateFormat(<span class="hljs-string">&quot;yyyy-MM-dd&quot;</span>)</span>;<br>String s = simpleDateFormat.format(date);<br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-string">&quot;时间为====&quot;</span>+s);<br></code></pre></div></td></tr></table></figure>
<ul>
<li>Date转换为Calendar</li>
</ul>
<figure class="highlight pgsql"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs pgsql"><span class="hljs-type">Date</span> date2 = <span class="hljs-built_in">new</span> <span class="hljs-type">Date</span>();<br>Calendar cal2 = Calendar.getInstance();<br>cal2.setTime(date2);<br><span class="hljs-keyword">System</span>.<span class="hljs-keyword">out</span>.println(cal2.<span class="hljs-keyword">get</span>(Calendar.YEAR) +&quot;-&quot;+(cal2.<span class="hljs-keyword">get</span>(Calendar.MONTH)+<span class="hljs-number">1</span>)+&quot;-&quot;+cal2.<span class="hljs-keyword">get</span>(Calendar.DATE));<br></code></pre></div></td></tr></table></figure>
<p>例题：</p>
<p>从键盘输入一个日期，格式为yyyy-M-d</p>
<p>要求计算该日期与1949年10月1日距离多少天</p>
<p>例如：</p>
<p>用户输入了：1949-10-2 程序输出：1</p>
<p>用户输入了：1949-11-1 程序输出：31</p>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml">public static void main(String<span class="hljs-literal">[]</span> args) &#123;<br>        Calendar cal = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Calendar</span>.</span></span>get<span class="hljs-constructor">Instance()</span>;<br>        Scanner sc = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Scanner(<span class="hljs-params">new</span> BufferedInputStream(System.<span class="hljs-params">in</span>)</span>);<br>        String s = sc.next<span class="hljs-literal">()</span>;<br>        String<span class="hljs-literal">[]</span> str = s.split(<span class="hljs-string">&quot;-&quot;</span>);<br>        cal.set(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-params">str</span>[0])</span>, <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-params">str</span>[1])</span> - <span class="hljs-number">1</span>, <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-params">str</span>[2])</span>);<br>        Calendar standard = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Calendar</span>.</span></span>get<span class="hljs-constructor">Instance()</span>;<br>        standard.set(<span class="hljs-number">1949</span>, <span class="hljs-number">10</span> - <span class="hljs-number">1</span>, <span class="hljs-number">1</span>);<br>        long t1 = cal.get<span class="hljs-constructor">TimeInMillis()</span>;<br>        long t2 = standard.get<span class="hljs-constructor">TimeInMillis()</span>;<br>        <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println((t1 - t2)<span class="hljs-operator"> / </span>(<span class="hljs-number">1000</span><span class="hljs-operator"> * </span><span class="hljs-number">60</span><span class="hljs-operator"> * </span><span class="hljs-number">60</span><span class="hljs-operator"> * </span><span class="hljs-number">24</span>) + <span class="hljs-number">1</span>);<br>    &#125;<br></code></pre></div></td></tr></table></figure>
<h2 id="双端队列"><a href="#双端队列" class="headerlink" title="双端队列"></a>双端队列</h2><div class="hljs code-wrapper"><pre><code>    定义：（常用）
</code></pre></div>
<blockquote>
<p>Deque<Integer> q=new LinkedList<Integer>();</p>
</blockquote>
<p>LinkedList底层是链表，ArrayDeque底层是数组实现</p>
<ul>
<li><p><code>offerFirst / addFirst(Object e);</code> 队首插入</p>
</li>
<li><p><code>offerLast / addLast(Object e); </code>队尾插入</p>
</li>
<li><p><code>pollFirst(); </code>队首删除</p>
</li>
<li><p><code>pollLast(); </code>队尾删除</p>
</li>
<li><p><code>peekFirst(); </code>队首获取</p>
</li>
<li><p><code>peekLast(); </code>队尾获取</p>
</li>
</ul>
<h2 id="进制转换"><a href="#进制转换" class="headerlink" title="进制转换"></a>进制转换</h2><h3 id="其他进制字符串-gt-十进制整数"><a href="#其他进制字符串-gt-十进制整数" class="headerlink" title="其他进制字符串-&gt;十进制整数"></a>其他进制字符串-&gt;十进制整数</h3><ul>
<li>public static Integer valueOf(int i)</li>
<li>public static Integer valueOf(String s)</li>
<li>public static Integer valueOf(String s, int radix) - radix为s字符串符合的进制</li>
</ul>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml"><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(12)</span>);<span class="hljs-comment">//12</span><br> <br><span class="hljs-comment">// 十进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(<span class="hljs-string">&quot;12&quot;</span>)</span>);<span class="hljs-comment">//12</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(<span class="hljs-string">&quot;12&quot;</span>,10)</span>);<span class="hljs-comment">//12</span><br> <br><span class="hljs-comment">// 二进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(<span class="hljs-string">&quot;1100&quot;</span>, 2)</span>);<span class="hljs-comment">//12</span><br> <br><span class="hljs-comment">// 8进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(<span class="hljs-string">&quot;1100&quot;</span>, 8)</span>);<span class="hljs-comment">//576</span><br> <br><span class="hljs-comment">// 16进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>value<span class="hljs-constructor">Of(<span class="hljs-string">&quot;1100&quot;</span>, 16)</span>);<span class="hljs-comment">//4352</span><br></code></pre></div></td></tr></table></figure>
<p>同理，用 public static int parseInt(String s)或 public static int parseInt(String s, int radix)转换为int型</p>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml"><span class="hljs-comment">// 十进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;12&quot;</span>)</span>); <span class="hljs-comment">// 12</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;12&quot;</span>, 10)</span>); <span class="hljs-comment">// 12</span><br> <br><span class="hljs-comment">// 二进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;1100&quot;</span>, 2)</span>); <span class="hljs-comment">// 12</span><br> <br><span class="hljs-comment">// 8进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;1100&quot;</span>, 8)</span>); <span class="hljs-comment">// 576</span><br> <br><span class="hljs-comment">// 16进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;1100&quot;</span>, 16)</span>); <span class="hljs-comment">// 4352</span><br> <br><span class="hljs-comment">// 32进制字符串 =&gt; 十进制整数</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span>parse<span class="hljs-constructor">Int(<span class="hljs-string">&quot;1100&quot;</span>, 32)</span>); <span class="hljs-comment">// 33792</span><br></code></pre></div></td></tr></table></figure>
<h3 id="十进制整数-gt-其他进制字符串"><a href="#十进制整数-gt-其他进制字符串" class="headerlink" title="十进制整数-&gt;其他进制字符串"></a>十进制整数-&gt;其他进制字符串</h3><ul>
<li>public static String toBinaryString(int i) - 转二进制</li>
<li>public static String toOctalString(int i) - 转八进制</li>
<li>public static String toHexString(int i) - 转十六进制</li>
</ul>
<figure class="highlight reasonml"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs reasonml"><span class="hljs-built_in">int</span> n = <span class="hljs-number">12</span>;<br><span class="hljs-comment">// 十进制整数 -&gt; 十进制字符串</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span><span class="hljs-keyword">to</span><span class="hljs-constructor">String(<span class="hljs-params">n</span>)</span>);<span class="hljs-comment">// 12</span><br> <br><span class="hljs-comment">// 十进制整数 -&gt; 二进制字符串</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span><span class="hljs-keyword">to</span><span class="hljs-constructor">String(<span class="hljs-params">n</span>, 2)</span>);<span class="hljs-comment">// 1100</span><br> <br><span class="hljs-comment">// 十进制整数 -&gt; 8进制字符串</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span><span class="hljs-keyword">to</span><span class="hljs-constructor">String(<span class="hljs-params">n</span>, 8)</span>);<span class="hljs-comment">// 14</span><br> <br><span class="hljs-comment">// 十进制整数 -&gt; 16进制字符串</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span><span class="hljs-keyword">to</span><span class="hljs-constructor">String(<span class="hljs-params">n</span>, 16)</span>);<span class="hljs-comment">// c</span><br> <br><span class="hljs-comment">// 十进制整数 -&gt; 32进制字符串</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">System</span>.</span></span>out.println(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Integer</span>.</span></span><span class="hljs-keyword">to</span><span class="hljs-constructor">String(<span class="hljs-params">n</span>, 32)</span>);<span class="hljs-comment">// c</span><br></code></pre></div></td></tr></table></figure>
<h2 id="自定义排序"><a href="#自定义排序" class="headerlink" title="自定义排序"></a>自定义排序</h2><figure class="highlight arduino"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs arduino"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">String</span>[] args)</span> </span>&#123;<br>    <span class="hljs-keyword">String</span>[] arr = <span class="hljs-keyword">new</span> <span class="hljs-keyword">String</span>[] &#123;<span class="hljs-string">&quot;3&quot;</span>, <span class="hljs-string">&quot;22&quot;</span>, <span class="hljs-string">&quot;1111&quot;</span>&#125;;<br>    <span class="hljs-comment">// 按照长度降序</span><br>    Arrays.sort(arr, (s1, s2) -&gt; &#123;<br>        <span class="hljs-keyword">return</span> s2.length() - s1.length();<br>    &#125;);<br>    System.out.<span class="hljs-built_in">println</span>(Arrays.toString(arr));<br>&#125;<br></code></pre></div></td></tr></table></figure>
<h2 id="数组求和"><a href="#数组求和" class="headerlink" title="数组求和"></a>数组求和</h2><ul>
<li>Arrays工具类转stream再求和</li>
</ul>
<figure class="highlight smali"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs smali">int[]<span class="hljs-built_in"> array </span>=<span class="hljs-built_in"> new </span>int[]&#123;1,2,3&#125;;<br>Arrays.stream(array).sum();<br></code></pre></div></td></tr></table></figure>
<ul>
<li>for loop 求和，虽然代码量比上面的大一点，但是效率比上面的高很多，建议还是使用for loop求和，别搞花里胡哨的</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/JavaSE/">JavaSE</a>
                    
                  </div>
                
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/03/15/JavaSE/Java%20%E5%9C%A8Iterator%E4%B8%AD%20remove%20&amp;%20ConcurrentModificationException%E9%97%AE%E9%A2%98/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Java在Iterator中remove & ConcurrentModificationException问题</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/02/01/JavaSE/java%E4%B8%AD%E6%95%B0%E7%BB%84%E5%A4%9A%E7%A7%8D%E9%81%8D%E5%8E%86%E6%B1%82%E5%92%8C%E7%9A%84%E6%95%88%E7%8E%87%E5%88%86%E6%9E%90/">
                        <span class="hidden-mobile">java中数组多种遍历求和的效率分析</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     © 2019-2021 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.0/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "/local-search.xml";
      $('#local-search-input').on('click', function() {
        searchFunc(path, 'local-search-input', 'local-search-result');
      });
      $('#modalSearch').on('shown.bs.modal', function() {
        $('#local-search-input').focus();
      });
    })()
  </script>





  

  
    <!-- MathJax -->
    <script>
      MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        options: {
          renderActions: {
            findScript: [10, doc => {
              document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
                const display = !!node.type.match(/; *mode=display/);
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
                const text = document.createTextNode('');
                node.parentNode.replaceChild(text, node);
                math.start = { node: text, delim: '', n: 0 };
                math.end = { node: text, delim: '', n: 0 };
                doc.math.push(math);
              });
            }, '', false],
            insertedScript: [200, () => {
              document.querySelectorAll('mjx-container').forEach(node => {
                let target = node.parentNode;
                if (target.nodeName.toLowerCase() === 'li') {
                  target.parentNode.classList.add('has-jax');
                }
              });
            }, '', false]
          }
        }
      };
    </script>

    <script async src="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js" ></script>

  











<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
